package com.dfbz.demo03_集合与线程安全问题;

import java.util.ArrayList;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo01_测试ArrayList线程不安全问题 {
    public static void main(String[] args) {
        ArrayList<String> arr = new ArrayList<>();
        for (int j = 0; j < 200; ++j) {
            new Thread(() -> {
                for (int i = 0; i < 100; i++) {
                    arr.add("1");
                    try {
                        // 然线程安全问题更加突出
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    }
}
